home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Messaging Service Access Module / Internet PMSAM / Internet PMSAM source / gatewayput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-12  |  3.1 KB  |  113 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------
  2.  
  3. AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
  4. Mail Service Access Module
  5.  
  6. written by Steve Falkenburg-- MacDTS
  7. ©1991-1993 Apple Computer, Inc.
  8.  
  9. --------------
  10. change history
  11. --------------
  12.  
  13. SJF        02/19/93    update for beta build    b1
  14. SJF        10/29/92    update to a11            a11
  15. SJF        06/08/92    update to a8            a8
  16. SJF        02/15/92    first working version    a4.5
  17. SJF        10/16/91    initial coding            a3
  18.  
  19. ---------------------------------------------------------------------*/
  20.  
  21. #ifndef __OCE__
  22. #include <OCE.h>
  23. #endif
  24.  
  25. #ifndef __OCEMAIL__
  26. #include <OCEMail.h>
  27. #endif
  28.  
  29. #include "const.h"
  30. #include "gwerrors.h"
  31. #include "mytypes.h"
  32. #include "globals.h"
  33. #include "utils.h"
  34. #include "gatewaystuff.h"
  35. #include "spoolfromexternal.h"
  36. #include "authstuff.h"
  37. #include "errorhandling.h"
  38.  
  39. #include "gatewayput.h"
  40.  
  41.  
  42. // PeriodicCheckPut
  43. //
  44. // when the toolbox thinks that it's time to check for mail, this function is called, in addition
  45. // to being called on startup of the gateway
  46. //
  47. OSErr PeriodicCheckPut(void)
  48. {
  49.     short slotIndex,arrIndex;
  50.     SlotSpec *slotSpec;
  51.     OSErr err = noErr;
  52.     unsigned long dateTime;
  53.     
  54.     TraceExecution("\pPeriodicCheckPut");
  55.  
  56.     GetDateTime(&dateTime);    
  57.  
  58.     for (slotIndex = arrIndex = 0; (err==noErr) && (slotIndex<gNumSlots); arrIndex++) {
  59.         if ((gLocation != 0) && (gSlotDatabase[arrIndex].locationActive & MailLocationMask(gLocation))
  60.                 && gSlotDatabase[arrIndex].enabled) {    // if the slot is in use, process it
  61.             slotIndex++;
  62.             slotSpec = &gSlotDatabase[arrIndex];
  63.             if (slotSpec->dirIdentity.valid) {
  64.                 EnterAuthCriticalSection();    // don't allow locking of local identity while we're here
  65.                 if (TimeToCheckPut(&slotSpec->stdInfo.sendReceiveTimer,slotSpec->lastCheckPut,dateTime)) {
  66.                     err = DoSlotPut(slotSpec);
  67.                     err = RetrySlotError(err,slotSpec,true);
  68.                     if (err==noErr)
  69.                         slotSpec->lastCheckPut = dateTime;
  70.                 }
  71.                 ExitAuthCriticalSection();
  72.             }
  73.         }
  74.         else slotIndex++;    // index past slots that are disabled
  75.     }
  76.     return err;
  77. }
  78.  
  79.  
  80. // TimeToCheckPut
  81. //
  82. // returns true if it's time to check for mail.  this function assumes the mailtimers are
  83. // in minutes, not seconds, since this seems to be what the toolbox is using for its scheduling
  84. // of eppcs.  note that the OCEMail.h header file specifies that these values are in seconds.
  85. //
  86. Boolean TimeToCheckPut(MailTimers *mailTimer,unsigned long lastCheck,unsigned long curTime)
  87. {
  88.     DateTimeRec dtRec;
  89.     unsigned long midnightSecs;    
  90.  
  91.     switch (mailTimer->receiveTimeKind) {
  92.         case kMailTimerOff:
  93.             return false;                    // never check if there is no interval
  94.             break;
  95.         case kMailTimerFrequency:            // check if past frequency+lastCheck
  96.             if (mailTimer->receive.frequency==0)
  97.                 return false;
  98.             return ((lastCheck + (60*mailTimer->receive.frequency))<curTime);
  99.             break;
  100.         case kMailTimerTime:                // check at a specific time
  101.             if ((lastCheck + kOneDaySecs) > curTime)
  102.                 return false;
  103.             Secs2Date(curTime,&dtRec);    // get date of last midnight
  104.             dtRec.hour = 0;
  105.             dtRec.minute = 0;
  106.             dtRec.second = 0;
  107.             Date2Secs(&dtRec,&midnightSecs);
  108.             return ( (midnightSecs+(60*mailTimer->receive.connectTime)) > curTime );
  109.             break;
  110.     }
  111.     return false;        
  112. }
  113.